package jsyf.oa.web.system;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import org.apache.commons.lang3.StringUtils;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ExportExcel;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.UserFacade;

/**
 * Created by Administrator on 2017/12/7 0007.
 */
@Api(value = "用户接口", description = "用户接口")
@Controller
@RequestMapping("/user")
public class UserController {


    @Resource
    private UserFacade userFacade;

   /* @Resource
    private JedisCluster jedisCluster;
*/

    /**
     * @description: 用户登陆
     * @author: @崔程鵬 @cuichengpeng
     * @creat: 13:20  2017/10/22
     * @since: V1.0.0
     * @see jsyf.oa.web
     */
    @ResponseBody
    @RequestMapping(value = "/login.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "用户登陆",
            notes = "用户登陆 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{tel:'15903434496',pwd:'123456'}", dataType = "String", paramType = "body")
    public void login(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        if (jsonParams != null && StringUtils.isNotBlank(jsonParams.getString("tel"))
                && StringUtils.isNotBlank(jsonParams.getString("pwd"))) {
            String result = this.userFacade.getUserViewByLogin(jsonParams);
            ResponseUtils.putJsonResponse(response, result);
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("手机号或密码不能为空"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过id查询用户",
            notes = "通过id查询用户 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void getById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        JSONObject records = this.userFacade.getById(jsonParams.getString("userId"));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
    }


    @ResponseBody
    @RequestMapping(value = "/updateWX.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "绑定微信",
            notes = "绑定微信 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void updateWX(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean records = this.userFacade.updateWX(jsonData);
        if (records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records.toString()));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("该微信已绑定其他账号"));

        }


    }

    @ResponseBody
    @RequestMapping(value = "/loginWX.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "微信登录",
            notes = "微信登录 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void loginWX(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        String result = this.userFacade.loginWX(jsonData);
        ResponseUtils.putJsonResponse(response, result);
    }


    /**
     * @description:模糊查询前10条用户信息
     * @author: 崔程鹏
     * @see jsyf.oa.web
     */
    @ResponseBody
    @RequestMapping(value = "/getTop10ByNameUser.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "根据用户名模糊查询前10条数据列表",
            notes = " 根据用户名模糊查询前10条数据列表  ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void getTop10ByNameUser(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        List<JSONObject> records = this.userFacade.getTop10ByNameUser(jsonParams);
        String result = "";
        if (records != null && records.size() > 0) {
            result = BaseUtils.succsessArrRespond(records);
        } else {
            result = BaseUtils.succsessArrRespond();
        }
        ResponseUtils.putJsonResponse(response, result);
    }


    /**
     * 模糊查询前10条用户信息,包括已经离职人员
     *
     * @param request
     * @param response
     * @param jsonData
     */
    @ResponseBody
    @RequestMapping(value = "/getCosterTop10ByNameUser.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "根据用户名模糊查询前10条数据列表,包括已经离职人员",
            notes = " 根据用户名模糊查询前10条数据列表，包括已经离职人员  ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void getCosterTop10ByNameUser(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        List<JSONObject> records = this.userFacade.getCosterTop10ByNameUser(jsonParams);
        String result = "";
        if (records != null && records.size() > 0) {
            result = BaseUtils.succsessArrRespond(records);
        } else {
            result = BaseUtils.succsessArrRespond();
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    /**
     * @description:查询下级用户
     * @author: @崔程鹏 @cuichengpeng
     * @see jsyf.oa.web
     */
    @ResponseBody
    @RequestMapping(value = "/getInferiorByParentId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询下级用户",
            notes = " 查询下级用户  ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")

    public void getInferiorByParentId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        String parentId = jsonParams.getString("parentId");
        List<JSONObject> resultList = this.userFacade.getInferiorByParentId(parentId);
        String result = "";
        if (resultList != null && resultList.size() > 0) {
            result = BaseUtils.succsessArrRespond(resultList);
        } else {
            result = BaseUtils.succsessArrRespond();
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    /**
     * @description:查询下级用户
     * @author: @崔程鹏 @cuichengpeng
     * @see jsyf.oa.web
     */
    @ResponseBody
    @RequestMapping(value = "/getSubordinateByParentId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询所有下级用户",
            notes = " 查询所有下级用户  ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")

    public void getSubordinateByParentId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {

        List<JSONObject> resultList = this.userFacade.getSubordinateByParentId(jsonData);
        String result = "";
        if (resultList != null && resultList.size() > 0) {
            result = BaseUtils.succsessArrRespond(resultList);
        } else {
            result = BaseUtils.succsessArrRespond();
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    /**
     * @description:查询能看见的人
     * @author:刘腾
     * @see jsyf.oa.web
     */
    @ResponseBody
    @RequestMapping(value = "/getVisiblePerson.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询能看见的人",
            notes = " 查询能看见的人  ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")

    public void getVisiblePerson(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {

        List<JSONObject> resultList = this.userFacade.getVisiblePerson(jsonData);
        String result = "";
        if (resultList != null && resultList.size() > 0) {
            result = BaseUtils.succsessArrRespond(resultList);
        } else {
            result = BaseUtils.succsessArrRespond();
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    @ResponseBody
    @RequestMapping(value = "/getRemind.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "用户提醒感叹号",
            notes = " 用户提醒感叹号  ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")

    public void getRemind(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject results = this.userFacade.getRemind(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(results));
    }

    @ResponseBody
    @RequestMapping(value = "/getEntourage.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询陪同人员",
            notes = " 查询陪同人员",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")

    public void getEntourage(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        String userId = jsonParams.getString("userId");
        JSONObject jsonObject = userFacade.getUserViewById(userId);
        String areaType = jsonObject.getString("areaType");
        String frontFlag = jsonObject.getString("frontFlag");
        String result = "";
        if (frontFlag.equals("1")) {
            if (areaType.equals("0")||areaType.equals("3")) {
                List<JSONObject> resultList = this.userFacade.getSuperiorByUserId(userId);
                if (resultList != null && resultList.size() > 0) {
                    result = BaseUtils.succsessArrRespond(resultList);
                    ResponseUtils.putJsonResponse(response, result);
                } else {
                    result = BaseUtils.succsessArrRespond();
                    ResponseUtils.putJsonResponse(response, result);
                }
            } else {
                List<JSONObject> resultList = this.userFacade.getInferiorByParentId(userId);
                if (resultList != null && resultList.size() > 0) {
                    result = BaseUtils.succsessArrRespond(resultList);
                    ResponseUtils.putJsonResponse(response, result);
                } else {
                    result = BaseUtils.succsessArrRespond();
                    ResponseUtils.putJsonResponse(response, result);
                }
            }
        } else {
            result = BaseUtils.succsessArrRespond();
            ResponseUtils.putJsonResponse(response, result);
        }


    }

    /**
     * @param response
     * @param jsonData
     * @Description: 保存/修改人员  <br/>
     * @return: void
     * @throw:
     * @author: 崔程鵬
     * @createTime: 2017/11/27 0027 10:18
     * @Version: V1.0.0
     */
    @RequestMapping(value = "/saveUser.json", method = RequestMethod.POST)
    public void saveUser(HttpServletResponse response, @RequestBody String jsonData) {
       String resultId = this.userFacade.saveUser(jsonData);
       String result="";
        if ("".equals(resultId)) {
            result = BaseUtils.errorrRespond("手机号已存在");
        } else {
            JSONObject obj = new JSONObject();
            obj.put("id", resultId);
            result = BaseUtils.succsessObjRespond(obj);
        }
        ResponseUtils.putJsonResponse(response, result);

    }

    @RequestMapping(value = "/appUpdateUser.json", method = RequestMethod.POST)
    public void appUpdateUser(HttpServletResponse response, @RequestBody String jsonData) {
        String resultId = this.userFacade.appUpdateUser(jsonData);
        String result = "";
        if ("".equals(resultId)) {
            result = BaseUtils.errorrRespond("修改个人信息失败");
        } else {
            JSONObject obj = new JSONObject();
            obj.put("id", resultId);
            result = BaseUtils.succsessObjRespond(obj);
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    @RequestMapping(value = "/updateFileNo.json", method = RequestMethod.POST)
    public void updateFileNo(HttpServletResponse response, @RequestBody String jsonData) {
        String resultId = this.userFacade.updateFileNo(jsonData);
        String result = "";
        if ("".equals(resultId)) {
            result = BaseUtils.errorrRespond("手机号已存在");
        } else {
            JSONObject obj = new JSONObject();
            obj.put("id", resultId);
            result = BaseUtils.succsessObjRespond(obj);
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    /**
     * @param response
     * @param jsonData
     * @Description: 根据ID逻辑删除人员  <br/>
     * @return: void
     * @throw:
     * @author: 崔程鵬
     * @createTime: 2017/11/24 0024 15:14
     * @Version: V1.0.0
     */
    @RequestMapping(value = "/deleteUser.json", method = RequestMethod.POST)
    public void deleteUser(HttpServletResponse response, @RequestBody String jsonData) {
        String result = this.userFacade.deleteUserByLeave(jsonData);
        ResponseUtils.putJsonResponse(response, result);
    }

    /**
     * @description: 通过传过来的手机号进行判断
     * @author: @崔程鵬 @cuichengpeng
     * @creat: 14:02  2017/12/13 0013
     * @since: V1.0.0
     * @see jsyf.oa.web
     */
    @RequestMapping(value = "/getUserByTel.json", method = RequestMethod.POST)
    public void getUserByTel(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        String tel = jsonParams.getString("tel");
        Boolean resultBoolean = this.userFacade.getUserByTel(tel);
        JSONObject result = new JSONObject();
        result.put("isTel", resultBoolean);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(result));
    }

    /**
     * @description: 查询视图用户 根据id
     * @author: @崔程鵬 @cuichengpeng
     * @creat: 11:36  2017/12/6 0006
     * @since: V1.0.0
     * @see jsyf.oa.web
     */
    @RequestMapping(value = "/getUserViewById.json", method = RequestMethod.POST)
    public void getUserViewById(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(userFacade.getUserViewById(jsonParam.getString("id"))));
    }

    /**
     * @description: 获取直接上级
     * @author: @崔程鵬 @cuichengpeng
     * @creat: 19:46  2017/12/14 0014
     * @since: V1.0.0
     * @see jsyf.oa.web
     */
    @RequestMapping(value = "/getFirstParent.json", method = RequestMethod.POST)
    public void getFirstParent(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(userFacade.getFirstParent(jsonParam.getString("userId"))));
    }

    /**
     * @description: 获取所有上级
     * @author: @崔程鵬 @cuichengpeng
     * @creat: 19:47  2017/12/14 0014
     * @since: V1.0.0
     * @see jsyf.oa.web
     */
    @RequestMapping(value = "/getParentList.json", method = RequestMethod.POST)
    public void getParentList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) throws Exception {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        String userId = jsonParams.getString("userId");
        List<JSONObject> resultList = this.userFacade.getParentList(userId);
        String result = "";
        if (resultList != null && resultList.size() > 0) {
            result = BaseUtils.succsessArrRespond(resultList);
        } else {
            result = BaseUtils.succsessArrRespond();
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    @RequestMapping(value = "/getLowerLevelByUserId.json", method = RequestMethod.POST)
    public void getLowerLevelByUserId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) throws Exception {
        List<JSONObject> resultList = this.userFacade.getLowerLevelByUserId(jsonData);
        String result = "";
        if (resultList != null && resultList.size() > 0) {
            result = BaseUtils.succsessArrRespond(resultList);
        } else {
            result = BaseUtils.succsessArrRespond();
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    /**
     * @description: 获取直接上级支持
     * @author: @崔程鵬 @cuichengpeng
     * @creat: 19:46  2017/12/14 0014
     * @since: V1.0.0
     * @see jsyf.oa.web
     */
    @RequestMapping(value = "/getSupport.json", method = RequestMethod.POST)
    public void getSupport(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(userFacade.getFirstParent(jsonParam.getString("userId"))));
    }


    /**
     * @description: 获取用户所在区域
     * @author: @崔程鵬 @cuichengpeng
     * @creat: 20:41  2017/12/14 0014
     * @since: V1.0.0
     * @see jsyf.oa.web
     */
    @RequestMapping(value = "/getUserByUserId.json", method = RequestMethod.POST)
    public void getUserByUserId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        String userId = jsonParams.getString("userId");
        List<JSONObject> resultList = this.userFacade.getUserByUserId(userId);
        String result = "";
        if (resultList != null && resultList.size() > 0) {
            result = BaseUtils.succsessArrRespond(resultList);
        } else {
            result = BaseUtils.succsessArrRespond();
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    /**
     * @description: 清除session是否存在
     * @author: @崔程鵬 @cuichengpeng
     * @creat: 17:24  2017/12/16 0016
     * @since: V1.0.0
     * @see jsyf.oa.web
     */
    @RequestMapping(value = "/cleanRedis.json", method = RequestMethod.POST)
    public void cleanRedis(HttpServletRequest request, HttpSession session) {
        String result = (String) session.getAttribute("result");
        if (!StringUtils.isBlank(result)) {
            session.removeAttribute("result");
        }
    }

    /**
     * @description: 获取redis
     * @author: @崔程鵬 @cuichengpeng
     * @creat: 16:56  2017/12/17 0017
     * @since: V1.0.0
     * @see jsyf.oa.web
     */

    @RequestMapping(value = "/getRedis.json", method = RequestMethod.POST)
    public void getRedis(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData,
                         HttpSession session) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        String tel = jsonParams.getString("tel");
        Object result = session.getAttribute(tel);
        if (result != null) {
            ResponseUtils.putJsonResponse(response, String.valueOf(result));
        } else {
            session.setAttribute("tel", tel);
        }
    }

    @RequestMapping(value = "/sort.json", method = RequestMethod.POST)
    public void sort(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        Boolean result = userFacade.sort(jsonParam.getString("userIds"));
        JSONObject objResult = new JSONObject();
        objResult.put("success", result);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(objResult));
    }


    @RequestMapping(value = "/getUserViewByCondition.json", method = RequestMethod.POST)
    public void getUserViewByCondition(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        JSONObject records;
        String requestPage;
        String pageSize;
        if (jsonParam.containsKey("requestPage") && jsonParam.containsKey("pageSize")) {
            requestPage = jsonParam.getString("requestPage");
            pageSize = jsonParam.getString("pageSize");
            records = this.userFacade.getUserViewByCondition(jsonParam, Integer.parseInt(requestPage), Integer.parseInt(pageSize));
        } else {
            requestPage = "1";
            pageSize = Integer.MAX_VALUE + "";
            records = this.userFacade.getUserViewByCondition(jsonParam, Integer.parseInt(requestPage), Integer.parseInt(pageSize));
        }
        if (records != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }

    }


    /**
     * @description: 获取兼职公司id
     * @author: @侯太雷 @cuichengpeng
     * @creat: 14:56  2018/3/7
     * @since: V1.0.0
     * @see jsyf.oa.web
     */
    @ResponseBody
    @RequestMapping(value = "/getCompanyIdsByUserId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "根据userId查询对应公司名称及id(包括兼职)",
            notes = " 根据userId查询对应公司名称及id(包括兼职)  ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void getCompanyIdsByUserId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        List<JSONObject> records = this.userFacade.getCompanyIdsByUserId(jsonParams);
        String result = "";
        if (records != null && records.size() > 0) {
            result = BaseUtils.succsessArrRespond(records);
        } else {
            result = BaseUtils.succsessArrRespond();
        }
        ResponseUtils.putJsonResponse(response, result);
    }

/*    @RequestMapping(value = "/getProUserList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "java调用存储过程",
            notes = "存储过程的调用",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    @ApiImplicitParam(name = "jsonData", value = "{uname:\"曹\"}", dataType = "String", paramType = "body")
    public void getProUserList(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParams = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        List<JSONObject> records = this.userFacade.getProUserList(jsonParams);
        String result = "";
        if (records != null && records.size() > 0) {
            result = BaseUtils.succsessArrRespond(records);
        } else {
            result = BaseUtils.succsessArrRespond();
        }
        ResponseUtils.putJsonResponse(response, result);
    }*/

   /* @RequestMapping(value = "validRadisData.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "检测radis缓存是否存在",
            notes = "检测radis缓存是否存在",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    @ApiImplicitParam(name = "jsonData", value = "{}", dataType = "String", paramType = "body")
    public void validRadisData(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        String tel = jsonObject.getString("tel");
        String pwd = jsonObject.getString("pwd");
        String record = "";
        String result = "";
        if (jedisCluster.exists("result_" + tel + pwd)) {
            record = jedisCluster.get("result_" + tel + pwd);
            result = BaseUtils.succsessObjRespond(result);
        }
        ResponseUtils.putJsonResponse(response, result);


    }*/


    @RequestMapping(value = "/getContacts.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取通訊錄",
            notes = "获取通訊錄",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getContacts(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        JSONObject result = this.userFacade.getContacts(jsonParam);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(result));
    }


    @RequestMapping(value = "/getDownByCondition.json", method = RequestMethod.GET)
    public void getDownByCondition(HttpServletRequest request, HttpServletResponse response, @RequestParam String userId) throws Exception {
        //查出来的数据
        List<JSONObject> records = this.userFacade.getDownList(userId);
        getDownExcel(records, response);
    }


    public void getDownExcel(List<JSONObject> jsonObjectList, HttpServletResponse response) throws Exception {
        //导出表名、列名
        String title = "通讯录列表";
        String[] rowsName = new String[]{"公司", "部门", "岗位", "姓名", "区域", "状态", "电话", "邮箱", "车牌"};
        List<Object[]> dataList = new ArrayList<Object[]>();
        Object[] objs = null;
        for (int i = 0; i < jsonObjectList.size(); i++) {
            JSONObject jsonObject = jsonObjectList.get(i);
            objs = new Object[rowsName.length];
            objs[0] = jsonObject.get("companyName");
            objs[1] = jsonObject.get("departName");
            objs[2] = jsonObject.get("roleName");
            objs[3] = jsonObject.get("name");
            objs[4] = jsonObject.get("regionName");
            //objs[4] = jsonObject.get("jobState");
            if (jsonObject.get("jobState").equals(0)) {
                objs[5] = "在职";
            } else if (jsonObject.get("jobState").equals(-1)) {
                objs[5] = "试用";
            } else {
                objs[5] = "试岗";
            }
            objs[6] = jsonObject.get("tel");
            objs[7] = jsonObject.get("email");
            objs[8] = jsonObject.get("carCard");
            dataList.add(objs);
        }
        ExportExcel ex = new ExportExcel(title, rowsName, dataList, response);
        ex.export();
    }

    @RequestMapping(value = "/RevertPinYin.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "插入拼音",
            notes = "插入拼音",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void RevertPinYin(HttpServletRequest request, HttpServletResponse response) {
        JSONObject obj = new JSONObject();
        obj.put("state", this.userFacade.RevertPinYin());
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(obj));
    }

    @RequestMapping(value = "/MD5Util.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "MD5加密",
            notes = "MD5加密",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void MD5Util(HttpServletRequest request, HttpServletResponse response) {
        JSONObject obj = new JSONObject();
        obj.put("state", this.userFacade.MD5Util());
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(obj));
    }

    @ResponseBody
    @RequestMapping(value = "/MD5Crack.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "MD5反转",
            notes = "MD5反转",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{MD5:'DD945A29C27BE569'}", paramType = "body")
    public void MD5Crack(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject obj = new JSONObject();
        obj.put("state", this.userFacade.MD5Crack(jsonData));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(obj));
    }

    @ResponseBody
    @RequestMapping(value = "/ForgetPwd.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "忘记密码 验证码",
            notes = "忘记密码 验证码",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{tel:'18234430448'}", paramType = "body")
    public void ForgetPwd(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        JSONObject obj = this.userFacade.ForgetPwd(jsonObject.getString("tel"));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(obj));
    }

    @ResponseBody
    @RequestMapping(value = "/yzmCheck.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "验证码验证",
            notes = "验证码验证 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{yzm:'2020',userId:'20180305170344DA83177DE6432D4E93'}", paramType = "body")
    public void yzmCheck(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = JSON.parseObject(jsonData);
        String userId = jsonObject.getString("userId");
        String date = jsonObject.getString("date");
        String result = this.userFacade.yzmCheck(jsonObject.getString("yzm"), userId);
        if ("1".equals(result)) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(result.toString()));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond(result));
        }
    }

    @RequestMapping(value = "/reEntry.json", method = RequestMethod.POST)
    public void reEntry(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject result = userFacade.reEntry(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(result));
    }
    @RequestMapping(value = "/lzSendMessage.json", method = RequestMethod.POST)
    public void lzSendMessage(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject result = userFacade.lzSendMessage(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(result));
    }

    @RequestMapping(value = "/updateAllUsersArchivaType.json", method = RequestMethod.POST)
    public void updateAllUsersArchivaType(HttpServletResponse response) {
        String result = this.userFacade.updateAllUsersArchivaType();
        if (!com.alibaba.dubbo.common.utils.StringUtils.isBlank(result)) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(result));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

}
